package com.example.boot3jetcahce.Controller;

import com.alicp.jetcache.Cache;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class TestController {

    @Resource(name = "userCache")
    Cache<Integer, String> userCache;

    @GetMapping("/cache/{id}")
    public String cache(@PathVariable("id") Integer id) {
        String test = userCache.get(id);
        if (test == null) {
            userCache.put(id, "数字" + id);
        }
        return userCache.get(id);
    }
}
